#ifndef TTS_INTERFACE_H
#define TTS_INTERFACE_H

#include <string>
#include <functional>
#include <atomic>
#include "aikit_biz_api.h"
#include "aikit_constant.h"
#include "aikit_biz_config.h"

class TTSInterface {
public:
    typedef std::function<void(const char* audioData, size_t dataLen)> AudioCallback;
    typedef std::function<void(const std::string& errorMsg)> ErrorCallback;
    typedef std::function<void()> CompletionCallback;

    TTSInterface(const std::string& role = "xiaofeng");
    ~TTSInterface();

    bool initialize();
    bool speak(const std::string& text);
    void setAudioCallback(AudioCallback callback);
    void setErrorCallback(ErrorCallback callback);
    void setCompletionCallback(CompletionCallback callback);
    void waitForCompletion();
    void cleanup();

private:
    static void OnOutput(AIKIT_HANDLE* handle, const AIKIT_OutputData* output);
    static void OnEvent(AIKIT_HANDLE* handle, AIKIT_EVENT eventType, const AIKIT_OutputEvent* eventValue);
    static void OnError(AIKIT_HANDLE* handle, int32_t err, const char* desc);

    std::string m_role;
    AIKIT_HANDLE* m_handle;
    static std::atomic_bool m_ttsFinished;
    static TTSInterface* m_instance;
    
    AudioCallback m_audioCallback;
    ErrorCallback m_errorCallback;
    CompletionCallback m_completionCallback;
    
    bool m_initialized;
};

#endif // TTS_INTERFACE_H